package com.example.owner.lettery1.base;

import android.content.Context;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import butterknife.ButterKnife;
import butterknife.Unbinder;

public abstract class BaseFragment extends Fragment {

    public View rootView;
    public LayoutInflater inflater;
    private Unbinder unbinder;
    private Context mContext;

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, Bundle savedInstanceState) {
        this.inflater = inflater;
        if (rootView == null) {
            rootView = inflater.inflate(this.getLayoutId(), container, false);
            unbinder = ButterKnife.bind(this, rootView);
            onInitView(rootView, savedInstanceState);
        }
        ViewGroup parent = (ViewGroup) rootView.getParent();
        if (parent != null) {
            parent.removeView(rootView);
        }
        mContext=getActivity();
        return rootView;
    }

    protected abstract void onInitView(View view, Bundle savedInstanceState);
    protected abstract int getLayoutId();

    @Override
    public void onDestroy() {
        unbinder.unbind();
        super.onDestroy();
    }
}
